package cn.sh.library.gmwx.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.sh.library.gmwx.dto.Pager;
import cn.sh.library.gmwx.dto.QueryResult;
import cn.sh.library.gmwx.service.RemoteService;
import cn.sh.library.gmwx.sparql.WorkSparql;

@Service
public class RemoteServiceImpl implements RemoteService {
    @Resource
    private WorkSparql workSparql;

    @Override
    public List<Map<String, String>> list(String person, Pager pager) {
        String order = "ORDER BY " + pager.getDir() + "(?" + pager.getSort() + ")";

        QueryResult<Map<String, String>> queryResult = this.workSparql.getRemotePersons(person, order, pager.getStartIndex(), pager.getPageSize());

        pager.calcPageCount(queryResult.getTotalrecord());
        pager.setRowCount(queryResult.getTotalrecord());
        return queryResult.getResultList();
    }
}
